Skip to content

Conversation

@yroeht
Copy link
Contributor

@yroeht yroeht commented Dec 21, 2022

This is to avoid the binary padding caused by placing sections after the .bss noload gap, which causes the binary to be unnecessarily large. By placing the noload .bss at the end, we do not have to include it in the binary.

Signed-off-by: Théophile Ranquet [email protected]

This is to avoid the binary padding caused by placing sections after the
.bss noload gap, which causes the binary to be unnecessarily large. By
placing the noload .bss at the end, we do not have to include it in the
binary.

Signed-off-by: Théophile Ranquet <[email protected]>
Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did basically the same thing for Cortex-M a while back. At the time, doing so broke userspace support, not sure if that is still the case -- see #21747.

@stephanosio stephanosio requested a review from ibirnbaum February 9, 2023 16:19
@MaureenHelm
Copy link
Member

@microbuilder can you take a look at this or reassign?

@stephanosio
Copy link
Member

@ibirnbaum @bbolen Can you please take a look?

@microbuilder
Copy link
Member

@microbuilder can you take a look at this or reassign?

Sorry, was waiting for feedback on comment from Stephanos, and fell off my radar since it wasn't tagged for 3.3.

@microbuilder
Copy link
Member

@MaureenHelm @stephanosio Can this wait until after the 3.3 release? Trying to sort out a workable solution to the TF-M release blocker issue.

@stephanosio
Copy link
Member

@MaureenHelm @stephanosio Can this wait until after the 3.3 release? Trying to sort out a workable solution to the TF-M release blocker issue.

Yes, this is not for 3.3.

@stephanosio stephanosio added this to the future milestone Feb 9, 2023
@ibirnbaum
Copy link
Member

As it happens, without remembering the existence of this PR, I ran into the same issue a few days ago after being generous with several heap settings and discovering that the resulting .bin image was unreasonably large. I'll cross-check with my modifications later today at the office, I think the padding issue wasn't just limited to .bss, but also to .noinit. It should also be checked if __data_region_end is somehow relevant for the MMU setup, as with the proposed change, the .bss section is now within the area marked with _image_ram_end / _end / z_mapped_end, but beyond whatever is supposed to be indicated with __data_region_end.

Copy link
Member

@ibirnbaum ibirnbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving just the .bss section to the end of the image doesn't fully resolve the padding issue, as memory areas such as thread stacks or heaps are placed in the .noinit section, which, at the time being, is located just behind .bss and therefore in the middle of the image.

A quick test with an application which reserves heaps with an approximate total size of 30 MB resulted in the following image sizes:

  • Linker command file as-is: 32.462.776
  • .bss moved to the end of the image: 22.977.152
  • both .bss and .noinit moved to the end of the image: 1.789.480

Therefore, the include statement for common-noinit.ld must be moved as well in order to fully resolve the padding issue.

With regards to the __data_region_end marker however, the behaviour is likely correct. This marker is used during startup in XIP operation mode when the initialized data sections are copied from flash to RAM. If the .bss and .noinit sections aren't contained in the flash, there's no point in copying random data from flash to RAM. Instead, .bss will be zeroed during early boot and .noinit is just left untouched.

@microbuilder
Copy link
Member

@yroeht Have time to reply to the feedback from @ibirnbaum ?

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@microbuilder
Copy link
Member

@povergoing Assigning this to you, hoping that you and @SgrrZhf can address this as part of #60031 since the current PR has gone unresponsive.

@ibirnbaum
Copy link
Member

@microbuilder @povergoing As this is a relatively small and quick fix, I'd suggest that I open a separate PR later tonight which replaces this one. We can easily merge this change before tackling 'the big one'.

@povergoing
Copy link
Member

@povergoing Assigning this to you, hoping that you and @SgrrZhf can address this as part of #60031 since the current PR has gone unresponsive.

Sure, and I saw that @ibirnbaum has already raised a fix for this.

@microbuilder @povergoing As this is a relatively small and quick fix, I'd suggest that I open a separate PR later tonight which replaces this one. We can easily merge this change before tackling 'the big one'.

Agreed, really appreciate it.

ibirnbaum added a commit to ibirnbaum/zephyr that referenced this pull request Aug 6, 2023
This is a follow up to zephyrproject-rtos#53262, which still lacked the adjustment of the
.noinit section's position within the binary by the time the PR went
stale.

Adjust the linker command file so that the .bss and .noinit sections
are placed at the end of the resulting binary. Until now, those sections
have been located somewhere in the middle of the binary, so that the
inclusion of structures like statically defined heaps or large zero-
initialized arrays reflected 1:1 in the resulting binary's size. Even
for a stripped binary, such data was included in full as the linker
couldn't omit it due to subsequent sections within the binary.

This fix has been tested with a 32 MB statically allocated heap and
a 32 MB uint8 zero-initialized array. Both structures are clearly
identifyable in the memory consumption statistics, however, the final
binary's size is unaffected by their inclusion.

Signed-off-by: Immo Birnbaum <[email protected]>
fabiobaltieri pushed a commit that referenced this pull request Aug 9, 2023
This is a follow up to #53262, which still lacked the adjustment of the
.noinit section's position within the binary by the time the PR went
stale.

Adjust the linker command file so that the .bss and .noinit sections
are placed at the end of the resulting binary. Until now, those sections
have been located somewhere in the middle of the binary, so that the
inclusion of structures like statically defined heaps or large zero-
initialized arrays reflected 1:1 in the resulting binary's size. Even
for a stripped binary, such data was included in full as the linker
couldn't omit it due to subsequent sections within the binary.

This fix has been tested with a 32 MB statically allocated heap and
a 32 MB uint8 zero-initialized array. Both structures are clearly
identifyable in the memory consumption statistics, however, the final
binary's size is unaffected by their inclusion.

Signed-off-by: Immo Birnbaum <[email protected]>
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 13, 2023
@github-actions github-actions bot closed this Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ARM ARM (32-bit) Architecture Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants